//
//  DeleteUserAlter.m
//  SleepingElf
//
//  Created by karong on 2023/11/9.
//

#import "DeleteUserAlter.h"
#import "WSGradientVertacilButton.h"

@interface DeleteUserAlter ()
@property (nonatomic, assign) NSInteger seconds;
@property (nonatomic, strong) NSTimer *timer;
@property (weak, nonatomic) IBOutlet WSGradientVertacilButton *confirmBtn;
@end

@implementation DeleteUserAlter

- (void)viewDidLoad {
    [super viewDidLoad];
    
}

- (void)layoutView {
    [super layoutView];
    self.confirmBtn.userInteractionEnabled = NO;
    [self startTime];
}

- (void)startTime {
    [self.confirmBtn setBackgroundColor:[UIColor colorFromHexRGB:@"F2F2F2"]];
    [self.confirmBtn setTitleColor:UIColor.font_gray_999999 forState:(UIControlStateNormal)];
    self.seconds = 5;
    [self.confirmBtn setTitle:SESF(@"%@(%lds)", WSLocalized(@"確認註銷"), self.seconds) forState:(UIControlStateNormal)];
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(countdown) userInfo:nil repeats:YES];
}

- (void)countdown {
    self.seconds -- ;
    [self.confirmBtn setTitle:SESF(@"%@(%lds)", WSLocalized(@"確認註銷"), self.seconds) forState:(UIControlStateNormal)];
    if(self.seconds <= 0) {
        // 倒计时结束
        [self skipStartScreenWithTrigger];
    }
}

- (void)skipStartScreenWithTrigger {
    [self.timer invalidate];
    self.timer = nil;
    self.confirmBtn.userInteractionEnabled = YES;
    [self.confirmBtn setTitle:WSLocalized(@"確認註銷") forState:(UIControlStateNormal)];
    [self.confirmBtn resetCorlor1:[UIColor colorFromHexRGB:@"4C69F3"] color2:[UIColor colorFromHexRGB:@"5045D7"]];
    [self.confirmBtn setTitleColor:[UIColor colorFromHexRGB:@"FFFFFF"] forState:(UIControlStateNormal)];
}

@end
